
package jfireeagle;

import java.math.*;
import java.util.StringTokenizer;

/**
 * 
 * 
 * This class uses decimal degrees (DD)
 * 
 * @see http://en.wikipedia.org/wiki/Geographic_coordinate_system
 * 
 * @see GpsBox
 * 
 */
public class GpsCoordinate
{

	private BigDecimal latitude;
	private BigDecimal longitude;

	public GpsCoordinate()
	{
		super();
	}
	
	/**
	 * 
	 * @param value "lat, lon" or "lat lon"
	 * 
	 */
	public GpsCoordinate(String value)
	{
		StringTokenizer tokenizer = new StringTokenizer(value, ",\n\t ");
		if (tokenizer.countTokens() != 2)
		{
			throw new IllegalArgumentException("bad arg: " + value);
		}
		
		this.setLatitude(new BigDecimal(tokenizer.nextToken()));
		
		this.setLongitude(new BigDecimal(tokenizer.nextToken()));
		
	}
	
	public GpsCoordinate(String lat, String lon)
	{
		latitude = new BigDecimal(lat);
		longitude = new BigDecimal(lon);
	}
	
	public GpsCoordinate(double lat, double lon)
	{
		this.latitude = new BigDecimal(lat);
		this.longitude = new BigDecimal(lon);
	}
	
	public BigDecimal getLatitude()
	{
		return latitude;
	}

	public void setLatitude(BigDecimal lat)
	{
		this.latitude = lat;
	}

	public BigDecimal getLongitude()
	{
		return longitude;
	}

	public void setLongitude(BigDecimal lon)
	{
		this.longitude = lon;
	}

	public String toString()
	{
		return this.getLatitude()
				+ " " 
				+ this.getLongitude();
	}
	
}
